Find & Replace using DXL

I am trying to write some DXL which will mimic some of the behaviour of the built-in DOORS find and replace dialog.

Ideally, I would like to be able to access the source code for the .inc files located in lib\dxl\standard\search (for example findreplace.inc), but the files appear to be encrypted.

I would like to write a DXL script which will allow the user to automatically locate cross-references to headings and to Table/Figure captions and replace them with an absolute object number reference, e.g. replace Table 1-2 with [XREF:nnnn] where nnnn is the absolute number.

How can I search for a specific regular expression across all objects within the module which will search in all attributes of the object?

I think I can setup a filter using the function:

Filter f = contents("(Table|Figure)", true, true)

But, I can't figure out if there's a way of determining which attribute it is that contains the text.

Does anyone know of a way to do this?


TheNybbler - Tue Dec 01 14:57:50 EST 2015

Re: Find & Replace using DXL
Mathias Mamsch - Tue Dec 01 17:23:29 EST 2015

With a filter I think you will not be able to get the attributes. You could use it for preselecting the objects, but why not use a simple loop over all objects over all attributes? Replacing part of a string has been described on the forum. Searching probably too. Any specific questions? Regards, Mathias

Re: Find & Replace using DXL
TheNybbler - Fri Dec 04 07:00:17 EST 2015

Mathias Mamsch - Tue Dec 01 17:23:29 EST 2015

With a filter I think you will not be able to get the attributes. You could use it for preselecting the objects, but why not use a simple loop over all objects over all attributes? Replacing part of a string has been described on the forum. Searching probably too. Any specific questions? Regards, Mathias

Hi Mathias,

I'm not sure how I would loop over all the attributes within an object. Could you please provide an example of this?

I'm pretty sure I can figure out how to search and replace part of a string though, and I've also found the relevant DXL functions that can be used to highlight objects and text within the module.

Thanks.

Re: Find & Replace using DXL
Mathias Mamsch - Fri Dec 04 07:36:38 EST 2015

TheNybbler - Fri Dec 04 07:00:17 EST 2015

Hi Mathias,

I'm not sure how I would loop over all the attributes within an object. Could you please provide an example of this?

I'm pretty sure I can figure out how to search and replace part of a string though, and I've also found the relevant DXL functions that can be used to highlight objects and text within the module.

Thanks.

Well out of my head:

AttrDef ad  = null;
Skip skAttrNames = createString()

for ad in current Module do {
    if (!ad.object) continue; // only use object attributes
    string attrName = ad.name;
    put (skAttrNames, attrName, attrName)
}

Object oSearch
Buffer attrVal = create();

for oSearch in entire current Module do {
    string attrName; 
    for attrName in skAttrNames do {
        attrVal = oSearch.attrName; // here you got the contents of the attributes
        // search ... do what you want
    }
}

Maybe that helps, regards, Mathias

Re: Find & Replace using DXL
TheNybbler - Fri Dec 04 11:54:41 EST 2015

Mathias Mamsch - Fri Dec 04 07:36:38 EST 2015

Well out of my head:

AttrDef ad  = null;
Skip skAttrNames = createString()

for ad in current Module do {
    if (!ad.object) continue; // only use object attributes
    string attrName = ad.name;
    put (skAttrNames, attrName, attrName)
}

Object oSearch
Buffer attrVal = create();

for oSearch in entire current Module do {
    string attrName; 
    for attrName in skAttrNames do {
        attrVal = oSearch.attrName; // here you got the contents of the attributes
        // search ... do what you want
    }
}

Maybe that helps, regards, Mathias

Many thanks Mathias, I can see how this will work.